package singleton;

public class SingletonTest03 {

    //instance使用了volatile，当某个线程改变instance时，会立即将值存到主存中
    private static volatile SingletonTest03 instance;

    private SingletonTest03(){

    }

    public static SingletonTest03 getInstance(){

        //查看主存中的instance是否为空
        if (instance == null){
            //此时对类加载加同步锁
            synchronized (SingletonTest03.class){
                //查看当前线程本地内存是否为空
                if (null == instance){
                    instance = new SingletonTest03();
                }
            }
        }
        return instance;
    }

}
